﻿using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using PMG.model;
using PMG.data;
using PMG.data.Tool;
using System.Text;
using System.IO;
using Newtonsoft.Json;
using log4net;

public partial class ADMINSurvey_Comsrv_StatSrv : ServerPage
{
    #region 注入对象
    private DaoANSWER _DaoANSWER;
    public DaoANSWER DaoANSWER
    {
        get { return _DaoANSWER; }
        set { _DaoANSWER = value; }
    }

    #endregion

    #region page_load
    protected void Page_Load(object sender, EventArgs e)
    {

        Client_Request();

    }
    #endregion

    #region 处理请求分支
    private void Client_Request()
    {
        #region oper
        if (Request["oper"] != null && Request["oper"] != string.Empty)
        {

            switch (Request["oper"])
            {
                case "GetStat":               //获得问卷
                    int id = int.Parse(Request["qid"]);
                    GetStat(id);
                    break;

                case "GetQuestion":               //获得问题
                    int qnid = int.Parse(Request["qnid"]);
                    GetQuestion(qnid);
                    break;

            }
        }
        #endregion
    }
    #endregion

    // ---------------------- sub action ------------ //
    #region 获得问题统计
    /// <summary>
    /// 获得问卷
    /// </summary>
    private void GetStat(int qid)
    {
        try
        {
            string strSql = "select label,dbo.fGetAnswerCount(questionid,[ID]) as num from Options where questionid = " + qid;
            DataSet ds = SqlHelper.GetDatasetSql(strSql);

            if (ds != null)
            {
                string Res = DataTable2Json(ds.Tables[0]);
                OutputJSon(Res);
            }
        }
        catch (Exception ex)
        {
            PMG.data.Tool.Logger.ErrorLog(ex.Source, ex.Message, "GetStat");
        }
    }
    #endregion


    #region 获得问题
    /// <summary>
    /// 获得问卷
    /// </summary>
    private void GetQuestion(int qnid)
    {
        try
        {
            string strSql = "select Id,QUESTION from QUESTION where questionnaireid = " + qnid;
            DataSet ds = SqlHelper.GetDatasetSql(strSql);

            if (ds != null)
            {
                string Res = DataTable2Json(ds.Tables[0]);
                OutputJSon(Res);
            }
        }
        catch (Exception ex)
        {
            PMG.data.Tool.Logger.ErrorLog(ex.Source, ex.Message, "GetStat");
        }
    }
    #endregion



}
